import { IPage, IReturnData, IPageData } from '../../type';

export default class CommonUtil {
  static paged({ pageIndex, pageSize, pageTotal }: IPage) {
    return {
      pageIndex,
      pageSize,
      pageTotal,
    };
  }
  static returnData<T = any>(val: T, page?: IPage): IReturnData<T> {
    return {
      code: 1,
      data: {
        content: val,
        page: page && this.paged(page),
      },
      msg: '',
    };
  }
  static returnPageData<T = any>(val: T[], page?: IPage): IPageData<T> {
    return {
      list: val,
      page: page && this.paged(page),
    };
  }
  static returnError(msg: string, code = 6001): IReturnData<null> {
    return {
      code,
      data: {
        content: null,
      },
      msg,
    };
  }
}
